/**
 * Copyright (c) 2015-present, Facebook, Inc.
 * All rights reserved.
 *
 * This source code is licensed under the BSD-style license found in the
 * LICENSE file in the root directory of this source tree. An additional grant
 * of patent rights can be found in the PATENTS file in the same directory.
 */

#import "AppDelegate.h"

#import <React/RCTBundleURLProvider.h>
#import <React/RCTRootView.h>

#import "RZMainViewController.h"

#import <TAKUUID.h>

@implementation AppDelegate

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
  
  NSDictionary* infoDict =[[NSBundle mainBundle] infoDictionary];
  NSString *uuid = [[TAKUUIDStorage sharedInstance] findOrCreate];
  if (!uuid) {
    NSUserDefaults *userDefault = [NSUserDefaults standardUserDefaults];
    uuid  = [userDefault objectForKey:@"uuid"];
    if (uuid == nil) {
      uuid = [[[NSUUID alloc] init] UUIDString];
      [userDefault setObject:uuid forKey:@"uuid"];
      [userDefault synchronize];
    }
  }
  
  NSDictionary *props = @{
                          @"uuid": uuid,
                          @"version": [infoDict objectForKey:@"CFBundleShortVersionString"]
                          };

  self.window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];

  UIViewController *rootViewController = [[RZMainViewController alloc] initWithProperties:props options:launchOptions];

  self.window.rootViewController = rootViewController;
  [self.window makeKeyAndVisible];
  return YES;
}

@end
